﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common.model.enumer;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.activities
{
    /// <summary>
    /// 古城寻宝
    /// </summary>
    class TreasureGameServer : LogicServer
    {
        public TreasureGameServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Treasure_Game; ServerReadableName = ConfigStrings.SR_Treasure_Game; }
        
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            frm.chk_treasure_game_enable.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");
            frm.txt_treasure_game_boxtype.Text = conf.ContainsKey(ConfigStrings.open_box_type) ? conf[ConfigStrings.open_box_type] : "";
            frm.txt_treasure_game_goldmove_boxtype.Text = conf.ContainsKey(ConfigStrings.gold_move_box_type) ? conf[ConfigStrings.gold_move_box_type] : "";

            int _minGoldSteps = 0;
            if (conf.ContainsKey(ConfigStrings.goldstep)) Int32.TryParse(conf[ConfigStrings.goldstep], out _minGoldSteps);
            frm.num_treasure_game_goldstep.Value = _minGoldSteps;

            frm.chk_treasure_game_use_ticket.Checked = conf.ContainsKey(ConfigStrings.use_ticket) && conf[ConfigStrings.use_ticket].ToLower().Equals("true");
            int ticket_type = 2;
            if(conf.ContainsKey(ConfigStrings.use_ticket_type)) Int32.TryParse(conf[ConfigStrings.use_ticket_type], out ticket_type);
            if (ticket_type > 3 || ticket_type < 1) ticket_type = 2;
            frm.combo_treasure_game_use_ticket_type.SelectedIndex = ticket_type - 1;
            frm.chk_treasure_game_ticket_gold_end.Checked = conf.ContainsKey(ConfigStrings.ticket_gold_end) && conf[ConfigStrings.ticket_gold_end].ToLower().Equals("true");
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_treasure_game_enable.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.open_box_type, frm.txt_treasure_game_boxtype.Text);
            conf.setConfig(ServerName, ConfigStrings.gold_move_box_type, frm.txt_treasure_game_goldmove_boxtype.Text);
            conf.setConfig(ServerName, ConfigStrings.goldstep, frm.num_treasure_game_goldstep.Value.ToString());

            conf.setConfig(ServerName, ConfigStrings.use_ticket, frm.chk_treasure_game_use_ticket.Checked.ToString());
            int ticket_type = frm.combo_treasure_game_use_ticket_type.SelectedIndex;
            if (ticket_type < 0) ticket_type = 0;
            ticket_type += 1; //1=玉石, 2=宝石, 3=兵器
            conf.setConfig(ServerName, ConfigStrings.use_ticket_type, ticket_type.ToString());
            conf.setConfig(ServerName, ConfigStrings.ticket_gold_end, frm.chk_treasure_game_ticket_gold_end.Checked.ToString());
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.open_box_type, "01");
            conf.setConfig(ServerName, ConfigStrings.gold_move_box_type, "");
            conf.setConfig(ServerName, ConfigStrings.goldstep, "0");
            conf.setConfig(ServerName, ConfigStrings.use_ticket, "true");
            conf.setConfig(ServerName, ConfigStrings.use_ticket_type, "2");
            conf.setConfig(ServerName, ConfigStrings.ticket_gold_end, "false");
            renderSettings();
        }
    }
}
